#include "game_version.h"


int __vstring(char *dest){
  #if CGAME_DEBUG == 1
    return __vstring(dest,CGAME_NAME,"Debug",CGAME_VERSION_MAJOR,CGAME_VERSION_MINOR,CGAME_VERSION_PATCH);
  #else
    return __vstring(dest,CGAME_NAME,"Release",CGAME_VERSION_MAJOR,CGAME_VERSION_MINOR,CGAME_VERSION_PATCH);
  #endif
}

int __vstring(char *dest,const char *name,const char *build,int major,int minor,int patch){
  return sprintf(dest,CGAME_VSTRING_FMT,name,major,minor,patch,build);
}

int __version(char *dest,const char *build,int major,int minor,int patch){
  return sprintf(dest,CGAME_VERSION_FMT,major,minor,patch,build);
}

int __version(char* dest){
  #if CGAME_DEBUG == 1
    return __version(dest,"Debug",CGAME_VERSION_MAJOR,CGAME_VERSION_MINOR,CGAME_VERSION_PATCH);
  #else
    return __version(dest,"Release",CGAME_VERSION_MAJOR,CGAME_VERSION_MINOR,CGAME_VERSION_PATCH);
  #endif
}

void __vprint(){
  __vprint(stdout);
}

void __vprint(FILE *stream){
  #if CGAME_DEBUG == 1
    fprintf(stream,CGAME_VSTRING_FMT,CGAME_NAME,CGAME_VERSION_MAJOR,CGAME_VERSION_MINOR,CGAME_VERSION_PATCH,"Debug");
  #else
    fprintf(stream,CGAME_VSTRING_FMT,CGAME_NAME,CGAME_VERSION_MAJOR,CGAME_VERSION_MINOR,CGAME_VERSION_PATCH,"Release");
  #endif
}

UINT32 __version(UINT8 major,UINT8 minor,UINT16 patch){
  return (major << 24) | ((minor << 16) & 0xFF0000) | (patch & 0x00FF);
}

void __version(CGameVersion_t* v,UINT32 val){
  v->_major = val >> 24;
  v->_minor = (val >> 16) & 0xFF;
  v->_patch = val & 0xFFFF;
}


